/*
######################################################################################################
#                                                                                                    # 
#	Author: Sharvan                                                                                  #     
#	Date: 9th Feb 2008                                                                               # 
#	Description: This user control place a WYSISYG Editor on page.                                   # 
    Javascript Folder: EditorImages
    Images Folder: Jscript
######################################################################################################
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// This code needs to be added to the control generating a postback, to retain the exsiting value of the 
/// editor
/// </summary>
/// <example>
///     <asp:Button ID="btn1" runat="server" Text="Click" OnClick="btn1_Click" OnClientClick="updateRTE('Editor1');" />
/// </example>
public partial class includes_Editor : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected string _rootPath;

    /// <summary>
    /// Path to Editor Folder
    /// This property sets the path of the js files
    /// </summary>
    /// <example>
    ///     http://<yourSiteName.com>/Editor/
    /// </example>    
    public string RootPath
    {        
        set { _rootPath = value; }
        get { return _rootPath; }
    }

    private int _height=400;

    /// <summary>
    /// This get/sets the height of Editor
    /// </summary>
    public int Height
    {
        get { return _height; }
        set { _height = value; }
    }

    private int _width=200;

    /// <summary>
    /// This get/sets the Width of Editor
    /// </summary>
    public int Width
    {
        get { return _width; }
        set { _width = value; }
    }

    protected  string _editorContent="";

    /// <summary>
    /// This property will be used to access the content of Editor
    /// </summary>
    public string EditorContent
    {
        get
        {
            if (Request.Form[this.ID] != null)
                _editorContent = rteSafe(Request.Form[this.ID]);
            if (_isHtmlEncodeDecode)
                return Server.HtmlEncode(_editorContent);
            else            
                return _editorContent;
        }
        set
        {
            if (_isHtmlEncodeDecode)
                _editorContent = Server.HtmlDecode(rteSafe(value));
            else
                _editorContent = rteSafe(value);

        }
    }

    private bool _isHtmlEncodeDecode;

    /// <summary>
    /// This property will be used to set the mode of Editor content
    /// IsHtmlEncodeDecode = true, encode the content of editor to html
    /// </summary>
    public bool IsHtmlEncodeDecode
    {
        get { return _isHtmlEncodeDecode; }
        set { _isHtmlEncodeDecode = value; }
    }

    string rteSafe(string str)
    {
        string tmpString = str;
        tmpString = tmpString.Replace(Convert.ToChar(145), Convert.ToChar(39));
        tmpString = tmpString.Replace(Convert.ToChar(146), Convert.ToChar(39));
        tmpString = tmpString.Replace("'", "&#39;");
        //	'convert all types of double quotes
        tmpString = tmpString.Replace(Convert.ToChar(147), Convert.ToChar(34));
        tmpString = tmpString.Replace(Convert.ToChar(148), Convert.ToChar(34));
        //	'replace carriage returns & line feeds
        tmpString = tmpString.Replace(Convert.ToChar(10), Convert.ToChar(" "));
        tmpString = tmpString.Replace(Convert.ToChar(13), Convert.ToChar(" "));
        return tmpString;
    }	
}
